<?php


namespace app\index\model;


use think\Db;
use think\Model;

class Examine extends Model
{
    /**
     * 用户投档的信息(封装数据库查询)
     * ywh开发
     * @param $human
     * @param $state
     * @param int $currPage
     * @return \think\db\Query[]|\think\Paginator
     * @throws \think\exception\DbException
     */
    public function userThrowMessage($human,$state,$currPage){
        return Db::table('examine')
            ->join(['official' => 'off'],'examine.official_id = off.official_id')
            ->join(['user' => 'user'],'user.user_id = off.user_id')
            ->join(['company' => 'company'],'company.company_id = off.company_id')
            ->join(['cotype' => 'type'],'type.company_id = company.company_id')
            ->field(['off.official_id','off.official','off.job_money','off.requirement','off.education'])
            ->field(['user.header','user.username'])
            ->field(['examine.state'])
            ->field(['company.company_id','company.company_logo','company.company_name','company.company_area'])
            ->field('type')
            ->where(['examine.user_id'   =>  $human, 'examine.state'       =>  $state])
            ->paginate(8,false,['page' => $currPage]);
    }

    /**
     * 用户投档页的获取用户投档的信息
     * ywh开发
     * @param $human
     * @param $state
     * @param $currPage
     * @return \think\db\Query[]|\think\Paginator
     * @throws \think\exception\DbException
     */
    public function userThrow($human,$state,$currPage = 1){
        return $this->userThrowMessage($human,$state,$currPage);
    }

    /**
     * 用户投档页，修改投档职位的信息
     * ywh开发
     * @param $human
     * @param $data
     * @return bool
     */
    public function userState($human,$data){
        if(!$this->where(['user_id' => $human , 'official_id' => $data['official_id']])->update(['state' => $data['state']])) return false;
        return true;
    }

    /**
     * 获取热职位信息
     * ywh开发
     */
    public function hot(){
        return Db::table('official')
            ->alias('off')
            ->join(['company'   =>  'company'],'off.company_id  =   company.company_id')
            ->field(['official_id','off.official','off.education','job_money','company.*'])
            ->orderRand()
            ->limit(5)
            ->select();
    }

    /**
     * @return mixed
     * ljj
     * 详细热招职位信息
     */
    public function getHotCompanyAttr($type,$city,$education)
    {
        return Db::table('official')
            ->alias('off')
            ->join(['company'   =>  'company'],'off.company_id  =   company.company_id')
            ->field(['off.official','off.education','company.*'])
            ->orderRand()
            ->limit(10)
            ->select();
    }

    public function isApply($userId,$offId)
    {
           return $this
            ->where('user_id','=',$userId)
            ->where('official_id','=',$offId)
            ->field('official_id')
            ->find();
    }
    public function HotOffBack($type='',$city='',$education='')
    {
        return Db::table('official')
            ->alias('off')
            ->join(['company'   =>  'company'],'off.company_id=company.company_id')
            ->join('classification class','class.official_id=off.official_id')
            ->where('class.class','like','%'.$type.'%')
            ->where('company.company_area','like','%'.$city.'%')
            ->where('off.education','like','%'.$education.'%')
            ->field(['off.official_id','off.official','off.education','company.*,class.class'])
            ->orderRand()
            ->limit(10)
            ->select();
    }

    public function getEmployAttr($companyid) {
        return $this
            ->alias('em')
            ->where('state','=',5)
            ->join(['official' => 'o'],'em.official_id = o.official_id')
            ->join(['company' => 'com'],'com.company_id = o.company_id')
            ->where('com.company_id','=',$companyid)
            ->field(['o.official','job_money'])
            ->select();
    }
}